package com.uxwine.alarm.main;

import com.uxwine.view.t.TimeView;
import com.uxwine.view.t.TimeView.TimerViewAdpater;

public class TSAdpater implements TimerViewAdpater{
	TimeView mView;
	int[] mnStates;
	int mnCurrent;
	int mnStart;
	Timer mTimer;
	
	public int getStart()
	{
		return mnStart;
	}
	
	public int getCurrent()
	{
		return mnCurrent;
	}
	
	public void setCurrent(int c)
	{
		mnCurrent = c;
		if(null == mnStates)
			return;
		for(int i = mnCurrent; i < mnStates.length; i++)
		{
			mnStates[i] = 0;
		}
	}
	
	public void setTimer(Timer t)
	{
		mTimer = t;
	}
	
	public Timer getTimer()
	{
		return mTimer;
	}
	
	public void setStates(int[] states)
	{
		mnStates = states;
		mnCurrent = 0;
		if(null == mnStates)
		{
			return;
		}
		for(int i = 0; i < states.length; i++)
		{
			if(states[i] == -1)
				continue;
			mnStart = i;
			mnCurrent = i;
			break;
		}
	}
	
	@Override
	public void setAdapterView(TimeView tv) {
		mView = tv;
	}

	@Override
	public void notifyDataChanged() {
		mView.updateView();
	}

	@Override
	public boolean isEnable(int index) {
		if(mnStates == null)
			return true;
		return mnStates[index] != -1;
	}

	@Override
	public boolean isSelected(int index) {
		if(mnStates == null)
			return false;
		return mnStates[index] == 1;
	}

	@Override
	public boolean isCurrent(int index) {
		return mnCurrent == index;
	}

	@Override
	public int getValue(int index) {
		if(null == mTimer)
			return 0;
		return mTimer.get(index);
	}
	
	public void setState(int index, int value)
	{
		if(null == mnStates)
			return;
		if(index < 0 || index > mnStates.length)
			return;
		mnStates[index] = value;
	}
	
	public void setState(int value)
	{
		setState(mnCurrent, value);
	}
	
	public void setSelected(boolean bSelected)
	{
		setState(bSelected ? 1 : 0);
	}
	
	public int getTotal()
	{
		if(mnStates == null)
			return 0;
		return mnStates.length;
	}
		
}
